﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using RA.Common;
using System.ComponentModel;
using GalaSoft.MvvmLight.Messaging;
using RA.UI.Messages;

namespace RA.UI.ViewModel
{
    public class SettingsViewModel : ViewModelBase
    {
        Settings _model;
        public SettingsViewModel(Settings settings)
        {
            _model = settings;
        }

        [Browsable(true), DisplayName("Метод"), Category("Настройки анализатора контуров")]
        public EMethod Method
        {
            get
            {
                return _model.Method;
            }
            set
            {
                if (_model.Method != value)
                {
                    _model.Method = value;
                    RaisePropertyChanged(() => Method);
                    BroadCastSettingsChanged();
                }
            }
        }

        [Browsable(true), DisplayName("Убрать шум"), Category("Настройки анализатора контуров")]
        public bool NoiseFilter
        {
            get
            {
                return _model.NoiseFilter;
            }
            set
            {
                if (_model.NoiseFilter != value)
                {
                    _model.NoiseFilter = value;
                    RaisePropertyChanged(() => NoiseFilter);
                    BroadCastSettingsChanged();
                }
            }
        }

        [Browsable(true), DisplayName("Размер блока порога"), Category("Настройки анализатора контуров")]
        public int AdaptiveThresholdBlockSize
        {
            get
            {
                return _model.AdaptiveThresholdBlockSize;
            }
            set
            {
                if (_model.AdaptiveThresholdBlockSize != value)
                {
                    _model.AdaptiveThresholdBlockSize = value;
                    RaisePropertyChanged(() => AdaptiveThresholdBlockSize);
                    BroadCastSettingsChanged();
                }
            }
        }

        [Browsable(true), DisplayName("Порог фильтрации"), Category("Настройки анализатора контуров")]
        public int CannyTreshold
        {
            get
            {
                return _model.CannyThreshold;
            }
            set
            {
                if (_model.CannyThreshold != value)
                {
                    _model.CannyThreshold = value;
                    RaisePropertyChanged(() => CannyTreshold);
                    BroadCastSettingsChanged();
                }
            }
        }

        [Browsable(true), DisplayName("Порог"), Category("Настройки анализатора контуров")]
        public double AdaptiveThresholdParameter
        {
            get
            {
                return _model.AdaptiveThresholdParameter;
            }
            set
            {
                if (_model.AdaptiveThresholdParameter != value)
                {
                    _model.AdaptiveThresholdParameter = value;
                    RaisePropertyChanged(() => AdaptiveThresholdParameter);
                    BroadCastSettingsChanged();
                }
            }
        }

        [Browsable(true), DisplayName("Минимальная площадь контура"), Category("Настройки анализатора контуров")]
        public int MinContourArea
        {
            get
            {
                return _model.MinContourArea;
            }
            set
            {
                if (_model.MinContourArea != value)
                {
                    _model.MinContourArea = value;
                    RaisePropertyChanged(() => MinContourArea);
                    BroadCastSettingsChanged();
                }
            }
        }

        [Browsable(true), DisplayName("Минимальная длина контура"), Category("Настройки анализатора контуров")]
        public int MinContourLength
        {
            get
            {
                return _model.MinContourLength;
            }
            set
            {
                if (_model.MinContourLength != value)
                {
                    _model.MinContourLength = value;
                    RaisePropertyChanged(() => MinContourLength);
                    BroadCastSettingsChanged();
                }
            }
        }

        [Browsable(true), DisplayName("Минимальный формфактор"), Category("Настройки анализатора контуров")]
        public double MinFormFactor
        {
            get
            {
                return _model.MinFormFactor;
            }
            set
            {
                if (_model.MinFormFactor != value)
                {
                    _model.MinFormFactor = value;
                    RaisePropertyChanged(() => MinFormFactor);
                    BroadCastSettingsChanged();
                }
            }
        }

        public void BroadCastSettingsChanged()
        {
            Messenger.Default.Send(new SettingsChangedMessage(_model));
        }
    }
}
